package com.example.api.service.impl;

import com.example.api.mapper.WarehouseMapper;
import com.example.api.model.entity.Warehouse;
import com.example.api.service.WarehouseService;
import com.example.api.utils.DataTimeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class WarehouseServiceImpl implements WarehouseService {

    @Resource
    private WarehouseMapper warehouseMapper;

    @Override
    public Warehouse save(Warehouse warehouse) {
        // 如果是新仓库，设置ID
        if (warehouse.getId() == null || warehouse.getId().isEmpty()) {
            warehouse.setId(UUID.randomUUID().toString());
        }
        warehouse.setCreateAt(DataTimeUtil.getNowTimeString());
        warehouseMapper.insert(warehouse);
        return warehouse;
    }

    @Override
    public List<Warehouse> findAll() {
        return warehouseMapper.findAll();
    }

    @Override
    public void delete(String id) {
        warehouseMapper.deleteById(id);
    }
}
